layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 司机评价管理
     */
    var TDispatchDriverEval = {
        tableId: "tDispatchDriverEvalTable"
    };

    /**
     * 初始化表格的列
     */
    TDispatchDriverEval.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'operateName', title: '所属项目'},
            {field: 'dispatchNumber', title: '调度单号'},
            {field: 'whLoadScore', title: '仓库-仓库装车'},
            {field: 'whServScore', title: '仓库-仓库服务'},
            {field: 'remark', title: '仓库-投诉建议'},
            {field: 'payFlag', title: '结算-拖欠运费'},
            {field: 'payRemark', title: '结算-投诉建议'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'createUserName', title: '创建人'},
            // {align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    TDispatchDriverEval.search = function () {
        var queryData = {};
        queryData['operateId'] = $("#operateId").val();
        queryData['dispatchNumber'] = $("#dispatchNumber").val();
        table.reload(TDispatchDriverEval.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };


    /**
     * 司机评价管理
     */
    var tDispatchDriverEval1 = {
        tableId: "tDispatchDriverEval1Table"
    };

    /**
     * 初始化表格的列
     */
    tDispatchDriverEval1.initColumn = function () {
        return [[
            {field: 'storeName', sort: true, title: '门店名称'},
            {field: 'unloadingSpeed', sort: true, title: '卸车速度评分'},
            {field: 'storeAttitude', sort: true, title: '门店态度评分'},
            {field: 'storeRemark', title: '投诉建议'},
        ]];
    };

    tDispatchDriverEval1.search = function () {
        var queryData = {};
        queryData['id'] = $("#mxId").val();
        table.reload(tDispatchDriverEval1.tableId, {
            where: queryData,
            done:function () {
            }
        });
    };

    // 单击行事件(点击入库单)
    table.on('row(' + TDispatchDriverEval.tableId + ')', function (obj) {
        var data = obj.data;
        $("#mxId").val(data.id);
        tDispatchDriverEval1.search();
    });


    /**
     * 弹出添加对话框
     */
    TDispatchDriverEval.openAddDlg = function () {
        window.location.href = Feng.ctxPath + '/tDispatchDriverEval/add';
    };

    /**
     * 导出excel按钮
     */
    TDispatchDriverEval.exportExcel = function () {
        var checkRows = table.checkStatus(TDispatchDriverEval.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    TDispatchDriverEval.openEditDlg = function (data) {
        window.location.href = Feng.ctxPath + '/tDispatchDriverEval/edit?id=' + data.id;
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    TDispatchDriverEval.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/tDispatchDriverEval/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(TDispatchDriverEval.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + TDispatchDriverEval.tableId,
        url: Feng.ctxPath + '/tDispatchDriverEval/list',
        page: true,
        limit: 20,
        height: "full-300",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: TDispatchDriverEval.initColumn()
    });

    // 渲染表格
    var tableResult1 = table.render({
        elem: '#' + tDispatchDriverEval1.tableId,
        url: Feng.ctxPath + '/tDispatchDriverEval/listMx',
        page: false,
        cellMinWidth: 100,
        cols: tDispatchDriverEval1.initColumn()
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        TDispatchDriverEval.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        TDispatchDriverEval.openAddDlg();
    });

    // 导出excel
    $('#btnExp').click(function () {
        TDispatchDriverEval.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + TDispatchDriverEval.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            TDispatchDriverEval.openEditDlg(data);
        } else if (layEvent === 'delete') {
            TDispatchDriverEval.onDeleteItem(data);
        }
    });
});
